﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
namespace He.DAL
{
	/// <summary>
	/// 数据访问类:resume
	/// </summary>
	public partial class resume
	{
		public resume()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQLite.GetMaxID("id", "he_resume"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from he_resume");
			strSql.Append(" where id=@id");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)
			};
			parameters[0].Value = id;

			return DbHelperSQLite.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(He.Model.resume model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into he_resume(");
			strSql.Append("job_title,name,sex,marry,birthday,height,school,degree,specialty,grad_year,census,expect_salary,phone,email,address,work_year,experience,add_time,attr_str,attr_str2,attr_num)");
			strSql.Append(" values (");
			strSql.Append("@job_title,@name,@sex,@marry,@birthday,@height,@school,@degree,@specialty,@grad_year,@census,@expect_salary,@phone,@email,@address,@work_year,@experience,@add_time,@attr_str,@attr_str2,@attr_num)");
			strSql.Append(";select LAST_INSERT_ROWID()");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@job_title", DbType.String),
					new SQLiteParameter("@name", DbType.String),
					new SQLiteParameter("@sex", DbType.String),
					new SQLiteParameter("@marry", DbType.String),
					new SQLiteParameter("@birthday", DbType.String),
					new SQLiteParameter("@height", DbType.String),
					new SQLiteParameter("@school", DbType.String),
					new SQLiteParameter("@degree", DbType.String),
					new SQLiteParameter("@specialty", DbType.String),
					new SQLiteParameter("@grad_year", DbType.String),
					new SQLiteParameter("@census", DbType.String),
					new SQLiteParameter("@expect_salary", DbType.String),
					new SQLiteParameter("@phone", DbType.String),
					new SQLiteParameter("@email", DbType.String),
					new SQLiteParameter("@address", DbType.String),
					new SQLiteParameter("@work_year", DbType.String),
					new SQLiteParameter("@experience", DbType.String),
					new SQLiteParameter("@add_time", DbType.String),
					new SQLiteParameter("@attr_str", DbType.String),
					new SQLiteParameter("@attr_str2", DbType.String),
					new SQLiteParameter("@attr_num", DbType.Int32,8)};
			parameters[0].Value = model.job_title;
			parameters[1].Value = model.name;
			parameters[2].Value = model.sex;
			parameters[3].Value = model.marry;
			parameters[4].Value = model.birthday;
			parameters[5].Value = model.height;
			parameters[6].Value = model.school;
			parameters[7].Value = model.degree;
			parameters[8].Value = model.specialty;
			parameters[9].Value = model.grad_year;
			parameters[10].Value = model.census;
			parameters[11].Value = model.expect_salary;
			parameters[12].Value = model.phone;
			parameters[13].Value = model.email;
			parameters[14].Value = model.address;
			parameters[15].Value = model.work_year;
			parameters[16].Value = model.experience;
			parameters[17].Value = model.add_time;
			parameters[18].Value = model.attr_str;
			parameters[19].Value = model.attr_str2;
			parameters[20].Value = model.attr_num;

			object obj = DbHelperSQLite.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(He.Model.resume model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update he_resume set ");
			strSql.Append("job_title=@job_title,");
			strSql.Append("name=@name,");
			strSql.Append("sex=@sex,");
			strSql.Append("marry=@marry,");
			strSql.Append("birthday=@birthday,");
			strSql.Append("height=@height,");
			strSql.Append("school=@school,");
			strSql.Append("degree=@degree,");
			strSql.Append("specialty=@specialty,");
			strSql.Append("grad_year=@grad_year,");
			strSql.Append("census=@census,");
			strSql.Append("expect_salary=@expect_salary,");
			strSql.Append("phone=@phone,");
			strSql.Append("email=@email,");
			strSql.Append("address=@address,");
			strSql.Append("work_year=@work_year,");
			strSql.Append("experience=@experience,");
			strSql.Append("add_time=@add_time,");
			strSql.Append("attr_str=@attr_str,");
			strSql.Append("attr_str2=@attr_str2,");
			strSql.Append("attr_num=@attr_num");
			strSql.Append(" where id=@id");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@job_title", DbType.String),
					new SQLiteParameter("@name", DbType.String),
					new SQLiteParameter("@sex", DbType.String),
					new SQLiteParameter("@marry", DbType.String),
					new SQLiteParameter("@birthday", DbType.String),
					new SQLiteParameter("@height", DbType.String),
					new SQLiteParameter("@school", DbType.String),
					new SQLiteParameter("@degree", DbType.String),
					new SQLiteParameter("@specialty", DbType.String),
					new SQLiteParameter("@grad_year", DbType.String),
					new SQLiteParameter("@census", DbType.String),
					new SQLiteParameter("@expect_salary", DbType.String),
					new SQLiteParameter("@phone", DbType.String),
					new SQLiteParameter("@email", DbType.String),
					new SQLiteParameter("@address", DbType.String),
					new SQLiteParameter("@work_year", DbType.String),
					new SQLiteParameter("@experience", DbType.String),
					new SQLiteParameter("@add_time", DbType.String),
					new SQLiteParameter("@attr_str", DbType.String),
					new SQLiteParameter("@attr_str2", DbType.String),
					new SQLiteParameter("@attr_num", DbType.Int32,8),
					new SQLiteParameter("@id", DbType.Int32,8)};
			parameters[0].Value = model.job_title;
			parameters[1].Value = model.name;
			parameters[2].Value = model.sex;
			parameters[3].Value = model.marry;
			parameters[4].Value = model.birthday;
			parameters[5].Value = model.height;
			parameters[6].Value = model.school;
			parameters[7].Value = model.degree;
			parameters[8].Value = model.specialty;
			parameters[9].Value = model.grad_year;
			parameters[10].Value = model.census;
			parameters[11].Value = model.expect_salary;
			parameters[12].Value = model.phone;
			parameters[13].Value = model.email;
			parameters[14].Value = model.address;
			parameters[15].Value = model.work_year;
			parameters[16].Value = model.experience;
			parameters[17].Value = model.add_time;
			parameters[18].Value = model.attr_str;
			parameters[19].Value = model.attr_str2;
			parameters[20].Value = model.attr_num;
			parameters[21].Value = model.id;

			int rows=DbHelperSQLite.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from he_resume ");
			strSql.Append(" where id=@id");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)
			};
			parameters[0].Value = id;

			int rows=DbHelperSQLite.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from he_resume ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQLite.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public He.Model.resume GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,job_title,name,sex,marry,birthday,height,school,degree,specialty,grad_year,census,expect_salary,phone,email,address,work_year,experience,add_time,attr_str,attr_str2,attr_num from he_resume ");
			strSql.Append(" where id=@id");
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)
			};
			parameters[0].Value = id;

			He.Model.resume model=new He.Model.resume();
			DataSet ds=DbHelperSQLite.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["job_title"]!=null && ds.Tables[0].Rows[0]["job_title"].ToString()!="")
				{
					model.job_title=ds.Tables[0].Rows[0]["job_title"].ToString();
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					model.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["sex"]!=null && ds.Tables[0].Rows[0]["sex"].ToString()!="")
				{
					model.sex=ds.Tables[0].Rows[0]["sex"].ToString();
				}
				if(ds.Tables[0].Rows[0]["marry"]!=null && ds.Tables[0].Rows[0]["marry"].ToString()!="")
				{
					model.marry=ds.Tables[0].Rows[0]["marry"].ToString();
				}
				if(ds.Tables[0].Rows[0]["birthday"]!=null && ds.Tables[0].Rows[0]["birthday"].ToString()!="")
				{
					model.birthday=ds.Tables[0].Rows[0]["birthday"].ToString();
				}
				if(ds.Tables[0].Rows[0]["height"]!=null && ds.Tables[0].Rows[0]["height"].ToString()!="")
				{
					model.height=ds.Tables[0].Rows[0]["height"].ToString();
				}
				if(ds.Tables[0].Rows[0]["school"]!=null && ds.Tables[0].Rows[0]["school"].ToString()!="")
				{
					model.school=ds.Tables[0].Rows[0]["school"].ToString();
				}
				if(ds.Tables[0].Rows[0]["degree"]!=null && ds.Tables[0].Rows[0]["degree"].ToString()!="")
				{
					model.degree=ds.Tables[0].Rows[0]["degree"].ToString();
				}
				if(ds.Tables[0].Rows[0]["specialty"]!=null && ds.Tables[0].Rows[0]["specialty"].ToString()!="")
				{
					model.specialty=ds.Tables[0].Rows[0]["specialty"].ToString();
				}
				if(ds.Tables[0].Rows[0]["grad_year"]!=null && ds.Tables[0].Rows[0]["grad_year"].ToString()!="")
				{
					model.grad_year=ds.Tables[0].Rows[0]["grad_year"].ToString();
				}
				if(ds.Tables[0].Rows[0]["census"]!=null && ds.Tables[0].Rows[0]["census"].ToString()!="")
				{
					model.census=ds.Tables[0].Rows[0]["census"].ToString();
				}
				if(ds.Tables[0].Rows[0]["expect_salary"]!=null && ds.Tables[0].Rows[0]["expect_salary"].ToString()!="")
				{
					model.expect_salary=ds.Tables[0].Rows[0]["expect_salary"].ToString();
				}
				if(ds.Tables[0].Rows[0]["phone"]!=null && ds.Tables[0].Rows[0]["phone"].ToString()!="")
				{
					model.phone=ds.Tables[0].Rows[0]["phone"].ToString();
				}
				if(ds.Tables[0].Rows[0]["email"]!=null && ds.Tables[0].Rows[0]["email"].ToString()!="")
				{
					model.email=ds.Tables[0].Rows[0]["email"].ToString();
				}
				if(ds.Tables[0].Rows[0]["address"]!=null && ds.Tables[0].Rows[0]["address"].ToString()!="")
				{
					model.address=ds.Tables[0].Rows[0]["address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["work_year"]!=null && ds.Tables[0].Rows[0]["work_year"].ToString()!="")
				{
					model.work_year=ds.Tables[0].Rows[0]["work_year"].ToString();
				}
				if(ds.Tables[0].Rows[0]["experience"]!=null && ds.Tables[0].Rows[0]["experience"].ToString()!="")
				{
					model.experience=ds.Tables[0].Rows[0]["experience"].ToString();
				}
				if(ds.Tables[0].Rows[0]["add_time"]!=null && ds.Tables[0].Rows[0]["add_time"].ToString()!="")
				{
					model.add_time=ds.Tables[0].Rows[0]["add_time"].ToString();
				}
				if(ds.Tables[0].Rows[0]["attr_str"]!=null && ds.Tables[0].Rows[0]["attr_str"].ToString()!="")
				{
					model.attr_str=ds.Tables[0].Rows[0]["attr_str"].ToString();
				}
				if(ds.Tables[0].Rows[0]["attr_str2"]!=null && ds.Tables[0].Rows[0]["attr_str2"].ToString()!="")
				{
					model.attr_str2=ds.Tables[0].Rows[0]["attr_str2"].ToString();
				}
				if(ds.Tables[0].Rows[0]["attr_num"]!=null && ds.Tables[0].Rows[0]["attr_num"].ToString()!="")
				{
					model.attr_num=int.Parse(ds.Tables[0].Rows[0]["attr_num"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,job_title,name,sex,marry,birthday,height,school,degree,specialty,grad_year,census,expect_salary,phone,email,address,work_year,experience,add_time,attr_str,attr_str2,attr_num ");
			strSql.Append(" FROM he_resume ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQLite.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM he_resume ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            object obj = DbHelperSQLite.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from he_resume T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQLite.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@tblName", DbType.VarChar, 255),
					new SQLiteParameter("@fldName", DbType.VarChar, 255),
					new SQLiteParameter("@PageSize", DbType.Int32),
					new SQLiteParameter("@PageIndex", DbType.Int32),
					new SQLiteParameter("@IsReCount", DbType.bit),
					new SQLiteParameter("@OrderType", DbType.bit),
					new SQLiteParameter("@strWhere", DbType.VarChar,1000),
					};
			parameters[0].Value = "he_resume";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

